using System;
using Dimebrain.TweetSharp.Core.Web;

namespace Dimebrain.TweetSharp.Fluent
{
    public abstract class TwitterLeafNodeBase : TwitterNodeBase, ITwitterLeafNode
    {
        protected TwitterLeafNodeBase(IFluentTwitter root) : base(root)
        {
        }

        public string AsUrl()
        {
            return Root.AsUrl();
        }

        public ITwitterLeafNode AuthenticateAs(string username, string password)
        {
            Root.AuthenticateAs(username, password);
            return this;
        }

        public ITwitterLeafNode CallbackTo(WebCallback callback)
        {
            Root.CallbackTo(callback);
            return this;
        }

        public ITwitterLeafNode RepeatEvery(TimeSpan timeSpan)
        {
            Root.RepeatEvery(timeSpan);
            return this;
        }

        public ITwitterLeafNode RepeatAfter(TimeSpan timeSpan, int times)
        {
            // todo
            Root.RepeatAfter(timeSpan, times);
            return this;
        }

#if !SILVERLIGHT
        public string Request()
        {
            return Root.Request();
        }
#endif

        public void RequestAsync()
        {
            Root.RequestAsync();
        }

        public ITwitterLeafNode AsXml()
        {
            Root.Format = WebFormat.Xml;
            return this;
        }

        public ITwitterLeafNode AsJson()
        {
            Root.Format = WebFormat.Json;
            return this;
        }

        public ITwitterLeafNode AsRss()
        {
            Root.Format = WebFormat.Rss;
            return this;
        }

        public ITwitterLeafNode AsAtom()
        {
            Root.Format = WebFormat.Atom;
            return this;
        }
    }
}